/*
* $Id: WizardStep.cpp 340 2011-10-20 08:08:01Z volok-aleksej@yandex.ru $
*
* Copyright 2009-2011 by Volokitin Aleksey
* All rights reserved
*
*/
#include "Common/include.h"
#include "WizardStep.h"

/*********************************************************************************/
/*                                  CWizardStep                                  */
/*********************************************************************************/
CWizardStep::CWizardStep(CWizardStep* pBack, CWnd* pParent)
: m_pBack(pBack), m_pParentWnd(pParent){}
CWizardStep::~CWizardStep(){
	for(std::vector<CWnd*>::iterator it = m_aWindows.begin(); it != m_aWindows.end(); it++)
		delete *it;
}
void CWizardStep::AddWindow(CWnd* pWindow){
	m_aWindows.push_back(pWindow);
}
void CWizardStep::RemoveWindow(CWnd* pWindow){
	for(std::vector<CWnd*>::iterator it = m_aWindows.begin(); it != m_aWindows.end(); it++){
		if(*it == pWindow){
			delete *it;
			m_aWindows.erase(it);
			break;
		}
	}
}
void CWizardStep::CloseWindows(){
	for(std::vector<CWnd*>::iterator it = m_aWindows.begin(); it != m_aWindows.end(); it++)
	{
		(*it)->DestroyWindow();
		delete *it;
	}
	m_aWindows.clear();
}

BEGIN_MESSAGE_HANDLER(CWizardStep)
END_MESSAGE_HANDLER()

/*********************************************************************************/
/*                              CWizardWarningStep                               */
/*********************************************************************************/
CWizardWarningStep::CWizardWarningStep(CWizardStep* pBack, CWnd* pParent)
: CWizardStep(pBack, pParent), m_pWarning(NULL){}
CWizardWarningStep::~CWizardWarningStep(){}
void CWizardWarningStep::Init(CPoint offset){
	InitMain(offset);
	InitWarning(offset);
}
void CWizardWarningStep::Update()
{
	HWND nextButton = GetDlgItem(m_pParentWnd->m_hWnd, ID_NEXT);
	BOOL bStarted = IsMainAppStarted();
	EnableWindow(nextButton, !bStarted);
	m_pWarning->ShowWindow(bStarted ? SW_SHOW : SW_HIDE);
}
bool CWizardWarningStep::IsMainAppStarted()
{
	HANDLE hProc = CCommonFunction::FindProcess(_T("Apiary.exe"));
	bool bres = hProc != INVALID_HANDLE_VALUE;
	CloseHandle(hProc);
	return bres;
}